<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Map,TreeMap,">










<meta name="description" content="&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TreeMap 是基于 NavigableMap 实现的红黑树 map 结构。该 map 中的数据根据数据元素的 key 的自然顺序或创建时提供的Comparator 进行排序。">
<meta name="keywords" content="Map,TreeMap">
<meta property="og:type" content="article">
<meta property="og:title" content="TreeMap">
<meta property="og:url" content="http://sangaizhi.gitee.io/2018/11/20/2018-11-20-TreeMap/index.html">
<meta property="og:site_name" content="sangaizhi-blog">
<meta property="og:description" content="&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TreeMap 是基于 NavigableMap 实现的红黑树 map 结构。该 map 中的数据根据数据元素的 key 的自然顺序或创建时提供的Comparator 进行排序。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://sangaizhi.gitee.io/2018/11/20/2018-11-20-TreeMap/rotate_left.gif">
<meta property="og:image" content="http://sangaizhi.gitee.io/2018/11/20/2018-11-20-TreeMap/rotate_right.gif">
<meta property="og:updated_time" content="2018-12-11T13:18:36.045Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="TreeMap">
<meta name="twitter:description" content="&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TreeMap 是基于 NavigableMap 实现的红黑树 map 结构。该 map 中的数据根据数据元素的 key 的自然顺序或创建时提供的Comparator 进行排序。">
<meta name="twitter:image" content="http://sangaizhi.gitee.io/2018/11/20/2018-11-20-TreeMap/rotate_left.gif">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://sangaizhi.gitee.io/2018/11/20/2018-11-20-TreeMap/">





  <title>TreeMap | sangaizhi-blog</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">sangaizhi-blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://sangaizhi.gitee.io/2018/11/20/2018-11-20-TreeMap/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="sangaizhi">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="sangaizhi-blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">TreeMap</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-11-20T14:33:06+08:00">
                2018-11-20
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TreeMap 是基于 NavigableMap 实现的红黑树 map 结构。该 map 中的数据根据数据元素的 key 的自然顺序或创建时提供的Comparator 进行排序。<br><a id="more"></a></p>
<h4 id="1、定义"><a href="#1、定义" class="headerlink" title="1、定义"></a>1、定义</h4><pre><code>TreeMap 实现了 NavigableMap、Cloneable、Serializable接口。继承了 AbstractMap.
继承 AbstractMap 表示 TreeMap 是一个支持映射表的 map。
实现 NavigableMap 接口表示它支持一系列的导航方法，有针对给定搜索条件返回最接近匹配的方法。
</code></pre><h4 id="2、有序性"><a href="#2、有序性" class="headerlink" title="2、有序性"></a>2、有序性</h4><pre><code>    TreeMap 是一个有序的 map,针对内部元素的排序，有两种方式，第一种方式，也是默认的方式，根据元素 key 的自然顺序进行
排序。第二种方式是根据我们在创建 Map的时候指定的 Comparator。
    注意，如果要正确的实现 Map 接口， 则有序映射所保持的顺序都必须与 equals 一致，关于这一点，在 Comparator 或者
Comparable 中有说明（强烈建议但不要求 x.compareTo(y) == 0 与 x.equals(y) 的结果相等）。为什么要求这一点，是
因为在 Map 中 比较两个键是否相等是根据 equals 方法比较的。
</code></pre><h4 id="3、非线程安全"><a href="#3、非线程安全" class="headerlink" title="3、非线程安全"></a>3、非线程安全</h4><pre><code>    TreeMap 中的方法不是同步的，所以TreeMap实现的数据结构不是线程安全，存在并发问题。因此，如果有多个线程访问同一个
TreeMap，并且至少有一个线程修改该 Map 的结构（是指添加或者删除一个或多个映射的操作，仅改变与现有键的关联值都不是结构上
的修改），那么我们必须在外部进行同步。对于外部同步，我们一般有两种办法：
    ①：对拥有该 Map 的对象的执行同步操作。
    ②：使用 Collections.synchronizedSortedMap(NavigableMap&lt;K,V&gt; m) 方法来包装该 map。当然，这个操作最好是
在创建时就完成。
</code></pre><h4 id="4、put-方法"><a href="#4、put-方法" class="headerlink" title="4、put 方法"></a>4、put 方法</h4><pre><code>put 方法主要分为以下几步：
①：类型和 null 值检查
②：寻找父节点（以根节点为初始节点，使用比较器（默认的或者指定的）比较插入节点与初始节点的 key, 以找到最合适插入节点
   的父节点）
③：插入节点
④：调整(修复、平衡)红黑树
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> V <span class="title">put</span><span class="params">(K key, V value)</span> </span>&#123;</span><br><span class="line">        Entry&lt;K,V&gt; t = root;</span><br><span class="line">        <span class="keyword">if</span> (t == <span class="keyword">null</span>) &#123;</span><br><span class="line">            <span class="comment">// ①：类型和 null 值检查</span></span><br><span class="line">            compare(key, key); <span class="comment">// type (and possibly null) check</span></span><br><span class="line">            <span class="comment">// 使用 key 和 value 创建新节点，并作为根节点插入</span></span><br><span class="line">            root = <span class="keyword">new</span> Entry&lt;&gt;(key, value, <span class="keyword">null</span>);</span><br><span class="line">            <span class="comment">// 更新容器大小</span></span><br><span class="line">            size = <span class="number">1</span>;</span><br><span class="line">            <span class="comment">// 更新修改次数</span></span><br><span class="line">            modCount++;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// ②：寻找父节点</span></span><br><span class="line">        <span class="comment">// 当前排序返回的结果</span></span><br><span class="line">        <span class="keyword">int</span> cmp;</span><br><span class="line">        Entry&lt;K,V&gt; parent;</span><br><span class="line">        <span class="comment">// 创建 TreeMap 时指定的比较器</span></span><br><span class="line">        Comparator&lt;? <span class="keyword">super</span> K&gt; cpr = comparator;</span><br><span class="line">        <span class="keyword">if</span> (cpr != <span class="keyword">null</span>) &#123;</span><br><span class="line">            <span class="comment">// 采用指定的比较器进行排序</span></span><br><span class="line">            <span class="keyword">do</span> &#123;  </span><br><span class="line">                <span class="comment">// 指向上一次循环后的节点</span></span><br><span class="line">                parent = t;</span><br><span class="line">                <span class="comment">// 比较当前节点的 key 与新增节点 key 的大小</span></span><br><span class="line">                cmp = cpr.compare(key, t.key);</span><br><span class="line">                <span class="keyword">if</span> (cmp &lt; <span class="number">0</span>)</span><br><span class="line">                    <span class="comment">// 如果新增节点的 key 比较当前节点的 key 小，则把当前节点的左子节点作为新的当前节点</span></span><br><span class="line">                    t = t.left;</span><br><span class="line">                <span class="keyword">else</span> <span class="keyword">if</span> (cmp &gt; <span class="number">0</span>)</span><br><span class="line">                    <span class="comment">// 如果新增节点的 key 比较当前节点的 key 大，则把当前节点的左右子节点作为新的当前节点</span></span><br><span class="line">                    t = t.right;</span><br><span class="line">                <span class="keyword">else</span></span><br><span class="line">                  <span class="comment">// 如果当前节点的 key 与新增节点的 key 相等，则替换当前节点的 value</span></span><br><span class="line">                    <span class="keyword">return</span> t.setValue(value);</span><br><span class="line">            &#125; <span class="keyword">while</span> (t != <span class="keyword">null</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">// 没有指定比较器，采用默认的比较器，具体的实现上面的使用指定比较器的方式相同</span></span><br><span class="line">            <span class="keyword">if</span> (key == <span class="keyword">null</span>)</span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> NullPointerException();</span><br><span class="line">            <span class="meta">@SuppressWarnings</span>(<span class="string">"unchecked"</span>)</span><br><span class="line">                Comparable&lt;? <span class="keyword">super</span> K&gt; k = (Comparable&lt;? <span class="keyword">super</span> K&gt;) key;</span><br><span class="line">            <span class="keyword">do</span> &#123;</span><br><span class="line">                parent = t;</span><br><span class="line">                cmp = k.compareTo(t.key);</span><br><span class="line">                <span class="keyword">if</span> (cmp &lt; <span class="number">0</span>)</span><br><span class="line">                    t = t.left;</span><br><span class="line">                <span class="keyword">else</span> <span class="keyword">if</span> (cmp &gt; <span class="number">0</span>)</span><br><span class="line">                    t = t.right;</span><br><span class="line">                <span class="keyword">else</span></span><br><span class="line">                    <span class="keyword">return</span> t.setValue(value);</span><br><span class="line">            &#125; <span class="keyword">while</span> (t != <span class="keyword">null</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// ③：插入节点</span></span><br><span class="line">        Entry&lt;K,V&gt; e = <span class="keyword">new</span> Entry&lt;&gt;(key, value, parent);</span><br><span class="line">        <span class="keyword">if</span> (cmp &lt; <span class="number">0</span>)</span><br><span class="line">            <span class="comment">// 如果插入节点的 key 比找到的父节点的 key 要小，则把插入节点作为找到的父节点的左节点进行插入</span></span><br><span class="line">            parent.left = e;</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">            <span class="comment">// 如果插入节点的 key 比找到的父节点的 key 要大，则把插入节点作为找到的父节点的右节点进行插入</span></span><br><span class="line">            parent.right = e;</span><br><span class="line">        <span class="comment">// ④： 调整（平衡、修复）红黑树</span></span><br><span class="line">        fixAfterInsertion(e);</span><br><span class="line">        size++;</span><br><span class="line">        modCount++;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<h4 id="5、fixAfterInsertion-方法"><a href="#5、fixAfterInsertion-方法" class="headerlink" title="5、fixAfterInsertion 方法"></a>5、fixAfterInsertion 方法</h4><pre><code>   由于 TreeMap 的存储结构是基于红黑树的。由于红黑树的特点（平衡），所以在插入某个元素节点后，都需要将TreeMap
的内部结构进行调整，以满足红黑树的特点。而 fixAfterInsertion 这个方法就是用来平衡、修复红黑树。
以下就是 fixAfterInsertion 方法在 JDK 1.8 中源码：
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">fixAfterInsertion</span><span class="params">(Entry&lt;K,V&gt; x)</span> </span>&#123;</span><br><span class="line">    <span class="comment">// 设置新增节点的颜色为红色</span></span><br><span class="line">    x.color = RED;</span><br><span class="line">    <span class="comment">// 循环到的节点 x 不等于空，不是根节点并且父节点的颜色是红色,父节点是黑色表示不需要修复</span></span><br><span class="line">    <span class="keyword">while</span> (x != <span class="keyword">null</span> &amp;&amp; x != root &amp;&amp; x.parent.color == RED) &#123;</span><br><span class="line">        <span class="comment">// 新增节点的父节点是作为左子节点</span></span><br><span class="line">        <span class="keyword">if</span> (parentOf(x) == leftOf(parentOf(parentOf(x)))) &#123;</span><br><span class="line">            Entry&lt;K,V&gt; y = rightOf(parentOf(parentOf(x))); <span class="comment">// 新增节点的叔叔节点</span></span><br><span class="line">            <span class="keyword">if</span> (colorOf(y) == RED) &#123; <span class="comment">// 如果叔叔节点是红色的</span></span><br><span class="line">                setColor(parentOf(x), BLACK); <span class="comment">// 把父节点设置成黑色</span></span><br><span class="line">                setColor(y, BLACK); <span class="comment">// 把叔叔节点设置成黑色</span></span><br><span class="line">                setColor(parentOf(parentOf(x)), RED); <span class="comment">// 把爷爷节点设置成红色</span></span><br><span class="line">                x = parentOf(parentOf(x)); <span class="comment">// 将爷爷节点作为新增的节点,相当于继续调整上面的节点</span></span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">              <span class="comment">// 叔叔节点是黑色</span></span><br><span class="line">                <span class="keyword">if</span> (x == rightOf(parentOf(x))) &#123; <span class="comment">// 新增的节点是其父节点的右子节点</span></span><br><span class="line">                    x = parentOf(x); <span class="comment">// 当前节点设置成其父节点</span></span><br><span class="line">                    rotateLeft(x); <span class="comment">// 左旋当前节点</span></span><br><span class="line">                &#125;</span><br><span class="line">                setColor(parentOf(x), BLACK); <span class="comment">// 设置当前节点的父节点的颜色黑色</span></span><br><span class="line">                setColor(parentOf(parentOf(x)), RED); <span class="comment">// 设置爷爷节点为红色</span></span><br><span class="line">                rotateRight(parentOf(parentOf(x))); <span class="comment">// 右旋爷爷节点</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            Entry&lt;K,V&gt; y = leftOf(parentOf(parentOf(x)));</span><br><span class="line">            <span class="keyword">if</span> (colorOf(y) == RED) &#123;</span><br><span class="line">                setColor(parentOf(x), BLACK);</span><br><span class="line">                setColor(y, BLACK);</span><br><span class="line">                setColor(parentOf(parentOf(x)), RED);</span><br><span class="line">                x = parentOf(parentOf(x));</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="keyword">if</span> (x == leftOf(parentOf(x))) &#123;</span><br><span class="line">                    x = parentOf(x);</span><br><span class="line">                    rotateRight(x);</span><br><span class="line">                &#125;</span><br><span class="line">                setColor(parentOf(x), BLACK);</span><br><span class="line">                setColor(parentOf(parentOf(x)), RED);</span><br><span class="line">                rotateLeft(parentOf(parentOf(x)));</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    root.color = BLACK;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<pre><code>左旋示意图（来源于网络）：
</code></pre><p><img src="/2018/11/20/2018-11-20-TreeMap/rotate_left.gif" alt="左旋示意图"><br>    右旋示意图（来源于网络）:<br><img src="/2018/11/20/2018-11-20-TreeMap/rotate_right.gif" alt="右旋示意图"></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Map/" rel="tag"># Map</a>
          
            <a href="/tags/TreeMap/" rel="tag"># TreeMap</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/11/19/2018-11-19-ConcurrentHashMap/" rel="next" title="ConcurrentHashMap">
                <i class="fa fa-chevron-left"></i> ConcurrentHashMap
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/11/24/2018-11-24-spring-social-principle/" rel="prev" title="Spring Social 介绍及原理">
                Spring Social 介绍及原理 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">sangaizhi</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">18</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">4</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">17</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            
            
              <div class="post-toc-content">  <ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#1、定义"><span class="nav-number">1.</span> <span class="nav-text">1、定义</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2、有序性"><span class="nav-number">2.</span> <span class="nav-text">2、有序性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3、非线程安全"><span class="nav-number">3.</span> <span class="nav-text">3、非线程安全</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4、put-方法"><span class="nav-number">4.</span> <span class="nav-text">4、put 方法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5、fixAfterInsertion-方法"><span class="nav-number">5.</span> <span class="nav-text">5、fixAfterInsertion 方法</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">sangaizhi</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
